package com.sdjz.dao;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;

import com.sdjz.domain.Student;

@Repository
public class StudentDao{
	
	@Autowired
	private HibernateTemplate hibernateTemplate;
	
	public void insert(Student student) {
		hibernateTemplate.save(student);
	}

	public void delete(Student student ) {
		hibernateTemplate.delete(student);
	}

	public void update(Student student) {
		hibernateTemplate.update(student);
	}

	@SuppressWarnings("unchecked")
	public List<Student> findByAll() {
		String hql = "from Student student order by student.id desc";
		return (List<Student>)(hibernateTemplate.find(hql));
	}

	public Student findById(Integer id) {
		return (Student)hibernateTemplate.get(Student.class, id);
	}
}
